import { Button, Space } from 'ant-design-vue'
import { tableColumns, orderStatusObj } from './data'

export function useColumns(updateFunction: Function, detailFunction: Function) {
  const getColumns = (column, record) => {
    if (column.dataIndex === 'orderNumber') {
      return <span>SR{record.orderNumber}</span>
    } else if (column.dataIndex === 'shopName') {
      return <span>{record.shopName}</span>
    } else if (column.dataIndex === 'orderStatus') {
      let orderStatusStr = ''
      orderStatusObj.forEach(model => {
        if (record.orderStatus == model.value) {
          orderStatusStr = model.label
        }
      })
      return <span>{orderStatusStr}</span>
    } else if (column.dataIndex === 'auditTime') {
      return <span>{record.auditTime}</span>
    } else if (column.dataIndex === 'receiveTime') {
      return <span>{record.receiveTime}</span>
    } else if (column.dataIndex === 'remark') {
      return <span>{record.remark}</span>
    } else if (column.dataIndex === 'createTime') {
      return <span>{record.createTime}</span>
    } else if (column.key === 'action') {
      return (
        <Space>
          <Button
            type='link'
            onClick={() => detailFunction(record.code, record.orderStatus)}
            v-auth={['warehouse:sale-return-order:detail']}
          >
            详情
          </Button>
          <Button
            type='link'
            onClick={() => updateFunction(record.code, record.orderStatus)}
            v-auth={['warehouse:sale-return-order:edit']}
          >
            编辑
          </Button>
        </Space>
      )
    }
  }
  return {
    getColumns,
    tableColumns
  }
}
